﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace zjbks
{
    public partial class AdminEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)//页面首次加载自动执行
            //{
            //    LoadData();
            //}
        }
        /// <summary>
        /// 加载数据信息
        /// </summary>
        public void LoadData()
        {
            //////string conditon = string.Empty;
            //////conditon = "(UserName is not null and UserName<>' ')";
            //////if (!string.IsNullOrEmpty(zh.Value))
            //////{
            //////    conditon += " and UserName='" + zh.Value + "'";
            //////}
            //////DALadmin_user dal = new DALadmin_user();
            //////IList<admin_userEntity> admins = dal.Getadmin_usersbyCondition(conditon);//按照条件来查询数据
            //////GridView1.DataSource = admins;
            //////GridView1.DataBind();
        }
        /// <summary>
        /// 按照账号执行查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            LoadData();
        }
        /// <summary>
        /// 当创建GridView行时，将行号绑定给当前行的LinkButton按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton lb1 = (LinkButton)e.Row.FindControl("lb1");
                lb1.CommandArgument = e.Row.RowIndex.ToString();//为每个操作对象设定行号信息。

                LinkButton lb2 = (LinkButton)e.Row.FindControl("lb2");
                lb2.CommandArgument = e.Row.RowIndex.ToString();

                LinkButton lb3 = (LinkButton)e.Row.FindControl("lb3");
                lb3.CommandArgument = e.Row.RowIndex.ToString();
            }
        }
        /// <summary>
        ///行内命令被触发的时候执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //int rowindex = int.Parse(e.CommandArgument.ToString());//获取操作行的行号
            //string Id = GridView1.DataKeys[rowindex].Value.ToString();//获取操作行数据的主键Id
            //DALadmin_user dal = new DALadmin_user();//定义针对admin_user表的操作对象

            //switch (e.CommandName)//获取操作对象的命令
            //{
            //    case "edit"://调转到编辑页面
            //        Response.Redirect("AdminEdit.aspx?id=" + Id);
            //        break;
            //    case "del"://删除用户
            //        dal.Deladmin_user(int.Parse(Id));
            //        LoadData();//重新加载数据，验证是否成功删除
            //        ShowInfo("数据删除成功！");
            //        break;
            //    case "reset"://修改密码
            //        admin_userEntity admin = dal.Getadmin_user(int.Parse(Id));
            //        admin.UserPassword = "123456";
            //        dal.Modadmin_user(admin);
            //        LoadData();//重新加载数据，验证是否重置
            //        ShowInfo("用户密码重置成功，新密码123456");
            //        break;

            //}
        }

        public void ShowInfo(string message)
        {
            //this.Page.RegisterStartupScript("a", "<script>" + message + "</script>");
        }
    }
}